//
//  RCDiscountDetailCell.m
//  RocketProject
//
//  Created by Wu Chengwei on 13-6-30.
//  Copyright (c) 2013年 Rocket. All rights reserved.
//

#import "RCDiscountDetailCell.h"
#import "UIColor-Expanded.h"
#import "CommonDefines.h"
#import "RCDiscountDataModel.h"
#import "NSString+NSString_Ex_.h"
#import "NSArray+EX.h"
#import <QuartzCore/QuartzCore.h>
#import "UIImageView+WebCache.h"

#define kBGImageFile             @"image_discount_cell_bg.png"
#define kLineImageFile           @"image_line_type3.png"


@interface RCDiscountDetailCell()

@property(nonatomic,retain) UIImageView *imgForStore;
@property(nonatomic,retain) UILabel *titleLabel;
@property(nonatomic,retain) UILabel *recommendLabel;
@property(nonatomic,retain) UILabel *tagLabel;
@property(nonatomic,retain) UILabel *distanceLabel;
@property(nonatomic,retain) UIImageView *lineImageView;

@end

@implementation RCDiscountDetailCell

@synthesize imgForStore= _imgForStore;
@synthesize titleLabel = _titleLabel;
@synthesize recommendLabel = _recommendLabel;
@synthesize tagLabel = _tagLabel;
@synthesize distanceLabel = _distanceLabel;
@synthesize lineImageView = _lineImageView;


- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        UIImage *bgImage = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:kBGImageFile ofType:nil]];
        self.layer.contents = (id)bgImage.CGImage;
        
//        self.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:kBGImageFile ofType:nil]]];
        [self createPlaceHolderView];
        // Initialization code
    }
    return self;
}

-(void)dealloc{
    self.imgForStore = nil;
    self.titleLabel = nil;
    self.recommendLabel = nil;
    self.tagLabel = nil;
    self.distanceLabel = nil;
    self.lineImageView = nil;
    [super dealloc];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

-(void)createPlaceHolderView{
    _imgForStore = [[UIImageView alloc]initWithFrame:CGRectMake(14, 17, 80, 60)];
    _imgForStore.backgroundColor = [UIColor clearColor];
    [self addSubview:_imgForStore];
    
    _titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(14+90, 17, 200, 16)];
    _titleLabel.backgroundColor = [UIColor clearColor];
    _titleLabel.textColor = [UIColor colorWithHex:0xff505050];
    _titleLabel.font = [UIFont fontWithName:kFontNameLightHeiti size:16];
    [self addSubview:_titleLabel];
    
    _recommendLabel = [[UILabel alloc]initWithFrame:CGRectMake(14+90, 39, 280-90, 13)];
    _recommendLabel.backgroundColor = [UIColor clearColor];
    _recommendLabel.textColor = [UIColor colorWithHex:0xffff6700];
    _recommendLabel.font = [UIFont fontWithName:kFontNameLightHeiti size:13];
    [self addSubview:_recommendLabel];
    
    _tagLabel = [[UILabel alloc]initWithFrame:CGRectMake(14+90, 64, 150, 12)];
    _tagLabel.backgroundColor = [UIColor clearColor];
    _tagLabel.textColor = [UIColor colorWithHex:0xff989797];
    _tagLabel.font = [UIFont fontWithName:kFontNameLightHeiti size:12];
    [self addSubview:_tagLabel];
    
    _distanceLabel = [[UILabel alloc]initWithFrame:CGRectMake(240, 64, 66, 12)];
    _distanceLabel.backgroundColor = [UIColor clearColor];
    _distanceLabel.textColor = [UIColor colorWithHex:0xff989797];
    _distanceLabel.textAlignment = UITextAlignmentRight;
    _distanceLabel.font = [UIFont fontWithName:kFontNameHelvetica size:12];
    [self addSubview:_distanceLabel];
    
    _lineImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 89, 320, 1)];
    _lineImageView.backgroundColor = [UIColor clearColor];
    NSString *filePath = [[[NSBundle mainBundle]resourcePath]stringByAppendingPathComponent:kLineImageFile];
    [_lineImageView setImage:[UIImage imageWithContentsOfFile:filePath]];
    [self addSubview:_lineImageView];
}

-(void)setContentWithData:(RCDiscountDetail *)detailData{
    if (nil == detailData) {
        return;
    }
    if (![NSString stringIsNullOrEmpty:detailData.itemName]) {
        _titleLabel.text = detailData.itemName;
    }else{
        _titleLabel.text = @"";
    }
    
    if (![NSString stringIsNullOrEmpty:detailData.recommendWord]) {
        _recommendLabel.text = detailData.recommendWord;
    }else{
        _recommendLabel.text = @"";
    }
    
    if (![NSString stringIsNullOrEmpty:detailData.distance]) {
        _distanceLabel.text = detailData.distance;
    }else{
        _distanceLabel.text = @"";
    }
    
    if (![NSString stringIsNullOrEmpty:detailData.tagName]) {
        _tagLabel.text = detailData.tagName;
    }else{
        _tagLabel.text = @"";
    }
    if (![NSString stringIsNullOrEmpty:detailData.picUrl]) {
        [_imgForStore setImageWithURL:[NSURL URLWithString:detailData.picUrl]];
    }

    
}

@end
